package cn.tedu.wufl.xcw.infrastructure.persistence;

import cn.tedu.wufl.xcw.dao.ContentDAO;
import cn.tedu.wufl.xcw.domain.bo.ContentBO;
import cn.tedu.wufl.xcw.infrastructure.data.converter.ContentConterver;
import cn.tedu.wufl.xcw.param.ContentParam;
import cn.tedu.wufl.xcw.po.Content;
import cn.tedu.wufl.xcw.repository.ContentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ContentRepositoryImpl implements ContentRepository {
    @Autowired
    private ContentDAO contentDAO;

    @Autowired
    private ContentConterver contentConterver;

    @Override
    public int insert(ContentParam contentParam) {
        Content content =contentConterver.paramToPo(contentParam);
        return contentDAO.insert(content);
    }

    @Override
    public int updateByPrimaryKey(ContentParam contentParam) {
        Content content = contentConterver.paramToPo(contentParam);
        System.out.println("------------11111--------"+content);
        return contentDAO.updateByPrimaryKey(content);
    }

    @Override
    public int delete(int id) {
        return contentDAO.delete(id);
    }

    @Override
    public List<ContentBO> findAll() {
        List<Content> list = contentDAO.selectAll();
        System.out.println("---------------");
        list.forEach(content -> System.out.println(content));
        List<ContentBO> contentBOList = contentConterver.poListToBOList(list);
        contentBOList.forEach(bo-> System.out.println(bo));
        System.out.println("11111111111111111111111111");
        return contentBOList;
    }

    @Override
    public ContentBO selectById(int contentId) {
        ContentBO contentBO = contentConterver.poToBo(contentDAO.selectByPrimaryKey(contentId));
        return contentBO;
    }
}
